package com.cy.hui_jie_dan.mapper;

import com.cy.hui_jie_dan.AutoFill.AutoFill;
import com.cy.hui_jie_dan.comon.enumeration.OperationType;
import com.cy.hui_jie_dan.popj.entity.User;
import com.cy.hui_jie_dan.popj.vo.tasksListVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * delete by primary key
     * @param userId primaryKey
     * @return deleteCount
     */
    int deleteByPrimaryKey(Integer userId);

    /**
     * insert record to table
     * @param record the record
     * @return insert count
     */
    int insert(User record);

    /**
     * insert record to table selective
     * @param record the record
     * @return insert count
     */
    int insertSelective(User record);

    /**
     * select by primary key
     * @param userId primary key
     * @return object by primary key
     */

    User selectByPrimaryKey(Integer userId);

    /**
     * update record selective
     * @param record the updated record
     * @return update count
     */
    @AutoFill(value = OperationType.UPDATE)
    int updateByPrimaryKeySelective(User record);

    /**
     * update record
     * @param record the updated record
     * @return update count
     */
    int updateByPrimaryKey(User record);
    @Select("select * from user where phone_number = #{phoneNumber}")
    User selectByPhone(String phoneNumber);
    @Update("update user set password = #{password} where user_id = #{currentId}  ")
    int updataPassWord(Long currentId,String password);
    @Select("select u.nickname, u.avatar,e.company_school CompanyName from user u,edit_profile e where u.user_id = e.user_id and e.user_id=#{userId} ")
    tasksListVO selectById(Integer userId);

    /**
     * Search users by keyword in nickname, phone number or personal experience
     * @param keyword the search keyword
     * @return list of users matching the keyword
     */
    @Select("select * from user where nickname like CONCAT('%', #{keyword}, '%') or phone_number like CONCAT('%', #{keyword}, '%') or personal_experience like CONCAT('%', #{keyword}, '%') limit 20")
    List<User> searchUsersByKeyword(String keyword);

    /**
     * Select users by a list of user IDs
     * @param userIds the list of user IDs
     * @return list of users with the given IDs
     */
    List<User> selectByUserIds(@Param("userIds") List<Integer> userIds);

    @Select("SELECT user_id, nickname, avatar FROM user WHERE user_id != #{myUserId}")
    List<User> selectAllExceptMe(@Param("myUserId") Integer myUserId);

    @Select("SELECT nickname from user where user_id=#{id}")
    String selectNicknameById(Integer id);
}